package org.example.java.base;

/**
 * 了解 Class.forName
 * 静态代码初始化顺序
 */
class A {
  A() {
    System.out.println("A构造方法.");
  }

  public static A getInstance() {
    System.out.println("A getInstance()");
    return new A();
  }
}

class B {
  public static A a = A.getInstance();

  static {
    System.out.println(a);
    System.out.println("B static block.");
  }
}

public class ClassForNameTest {

  private static class C {
    C() {
      System.out.println("C构造方法.");
    }

    static {
      System.out.println("C static block.");
    }

    public B getInstanceOfB() {
      System.out.println("getInstanceOfB()");
      return new B();
    }
  }

  public static void main(String[] args) throws Exception {
    Class test = Class.forName("com.hans.java.base.B");
    System.out.println(test.newInstance());
    Class c = C.class;
  }
}
